define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'clothmaking_packing/index/index' + location.search,
                    add_url: 'clothmaking_packing/index/add',
                    edit_url: 'clothmaking_packing/index/edit',
                    del_url: 'clothmaking_packing/index/del',
                    multi_url: 'clothmaking_packing/index/multi',
                    import_url: 'clothmaking_packing/index/import',
                    table: 'clothmaking_packing',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'paper', title: __('Paper')},
                        {field: 'innertag', title: __('Innertag'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'carton', title: __('Carton'), operate: 'LIKE'},
                        {field: 'doublingplate', title: __('Doublingplate'), operate: 'LIKE'},
                        {field: 'pepackaging', title: __('Pepackaging'), operate: 'LIKE'},
                        {field: 'card', title: __('Card'), operate: 'LIKE'},
                        {field: 'testreport', title: __('Testreport'), operate: 'LIKE'},
                        {field: 'labeling', title: __('Labeling'), operate: 'LIKE'},
                        {field: 'layers', title: __('Layers'), operate: 'LIKE'},
                        {field: 'pallet', title: __('Pallet'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'status', title: __('Status'), searchList: {"11":__('Status 11')}, formatter: Table.api.formatter.status},
                        {field: 'planid', title: __('Planid')},                       
                        {field: 'plan.productID', title: __('Plan.productid')},
                        {field: 'plan.createtime', title: __('Plan.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'plan.updatetime', title: __('Plan.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'plan.thickness_min', title: __('Plan.thickness_min')},
                        {field: 'plan.thickness_max', title: __('Plan.thickness_max')},
                        {field: 'plan.spring_min', title: __('Plan.spring_min')},
                        {field: 'plan.spring_max', title: __('Plan.spring_max')},
                        {field: 'plan.grain', title: __('Plan.grain')},
                        {field: 'plan.csamples', title: __('Plan.csamples')},
                        {field: 'plan.psamples', title: __('Plan.psamples')},
                        {field: 'plan.mark', title: __('Plan.mark'), operate: 'LIKE'},
                        {field: 'plan.quantity', title: __('Plan.quantity')},
                        {field: 'plan.delivery', title: __('Plan.delivery')},
                        {field: 'plan.status', title: __('Plan.status'), formatter: Table.api.formatter.status},
                        {field: 'plan.weigh', title: __('Plan.weigh')},
                        {field: 'plan.user_id', title: __('Plan.user_id')},
                        {field: 'plan.planid', title: __('Plan.planid')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
